<?php include '../../../entries/restful.php';
/**
 *  工作完成统计
 */
class Surface extends Restful{

    public function action(){

        $user = json_decode($this->session->getItem('user'),true);
        $batch_id = get('batch_id');
        $cmt_id = $user['cmt_id'];

        $sql = 'select amount,build_id,build_name,unit_id,unit_name from fee_order_temp where batch_id = ? and cmt_id = ?';
        $arg = [$batch_id,$cmt_id];
        $info = Mdb::query(MDB_MAIN,$sql,$arg);
        $obj = [];

        foreach($info as $val){
            if(isset($obj[$val['build_id'] . '_' . $val['unit_id']])) $obj[$val['build_id'] . '_' . $val['unit_id']] = ["build_name"=>$val['build_name'],"unit_name"=>$val['unit_name'],"finish"=>0,"all"=>0];
            if($val['amount'] != 0 ){
                $obj[$val['build_id'] . '_' . $val['unit_id']]['finish'] += 1; 
            }
            $obj[$val['build_id'] . '_' . $val['unit_id']]['all'] += 1; 
        }

        $list = [];
        foreach(array_keys($obj) as $key){
            $list[] = $obj[$key];
        }

        return Res::ok($list);
    }
}

new Surface();